package com.hongxun.design.BroadCastReceivers;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiManager;

import java.util.ArrayList;
import java.util.List;
import com.hongxun.design.BroadCastReceivers.WifiStateBroadCast.WifiBroadCastOperations;
import com.hongxun.design.MyApp;
import com.hongxun.design.mytools.MString;
import com.hongxun.design.mytools.MyLog;

/**
 * Created by zerdoor_pc on 2016/4/18.
 */
public class WifiScanRsultBroadCast  extends BroadcastReceiver {

    private WifiBroadCastOperations operations;

    private WifiManager mWifimanager;

    // 扫描网络连接列表
    private List<ScanResult> wifiList;

    public WifiScanRsultBroadCast(WifiBroadCastOperations operations) {

        this.operations = operations;

    }

    @Override
    public void onReceive(Context context, Intent intent) {

        if (intent.getAction().equalsIgnoreCase(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) {
            List<ScanResult> MyWifi =new ArrayList<>();
            mWifimanager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
            wifiList = mWifimanager.getScanResults();
            MyLog.L(MyApp.AppName + "WifiBroadCast" + "into onReceive(Context context, Intent intent)" + wifiList);
            for (int i=0;i<wifiList.size();i++){
                if (wifiList.get(i).SSID.contains(MString.HotHead)){
                    MyWifi.add(wifiList.get(i));
                }
            }
            MyLog.L(MyApp.AppName + "WifiBroadCast" + "into onReceive(Context context, Intent intent)" + MyWifi);
            operations.disPlayWifiScanResult(MyWifi);
        }
    }
}
